package com.csw.android.ffmpegtest.model

import com.csw.android.ffmpegtest.app.Config
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.schedulers.Schedulers
import java.io.File

object FileModel {

    fun getSection201WavFileList(): Observable<MutableList<File>> {
        return Observable.create<MutableList<File>> { it ->
            val wav = File(Config.Section201.WAV_PATH)
            val result = mutableListOf<File>()
            result.addAll(wav.listFiles())
            result.sortBy { file ->
                file.name
            }
            if (!it.isDisposed) {
                it.onNext(result)
            }
            if (!it.isDisposed) {
                it.onComplete()
            }
        }.subscribeOn(Schedulers.io())
    }

    fun getSection701AacFileList(): Observable<MutableList<File>> {
        return Observable.create<MutableList<File>> { it ->
            val aac = File(Config.Section701.AAC_PATH)
            val result = mutableListOf<File>()
            result.addAll(aac.listFiles())
            result.sortBy { file ->
                file.name
            }
            if (!it.isDisposed) {
                it.onNext(result)
            }
            if (!it.isDisposed) {
                it.onComplete()
            }
        }.subscribeOn(Schedulers.io())
    }
}